'''
@Descripttion: 
@version: 
@encoding: utf-8
@Author: qiurongcan
Date: 2025-09-05 20:14:29
LastEditTime: 2025-09-05 20:33:12
'''

from collections import deque


class Solution:

    def maxSlidingWindow(self, nums, k):
        
        dq = deque()
        res, n = [], len(nums)
        for i, j in zip(range(1 - k, 1 - k + n), range(n)):
            if i > 0 and dq[0] == nums[i - 1]:
                dq.popleft()

            # 保持一个始终递减的情况
            while dq and dq[-1] < nums[j]:
                dq.pop()
            
            dq.append(nums[j])
            
            if i >= 0:
                res.append(dq[0])
        
        return res
    

if __name__ == "__main__":

    nums = [1,3,-1,-3,5,3,6,7]
    k = 3
    sol = Solution()
    res = sol.maxSlidingWindow(nums, k)
    print(res)

